<?php

class TP_Service {
    public function __construct() {
        log_message('debug', "Service Class Initialized");
    }

    public function __get($key) {
        $CI = &get_instance();
        return $CI->$key;
    }



    // 获取redis实例
    public function newRedis() {
        $cfg = $this->__get('config')->item('redis');
        $redis = new Redis();
        $redis->connect($cfg['host'], $cfg['port']);
        $auth = $redis->auth($cfg['password']);
        if (!$auth) {
            exit(retJson(ErrCode::ErrCode_10012));
        }
        return $redis;
    }


    // 获取角色
    public function getRole($uuid) {
        $sql = sql_format("SELECT id, account_type, role_id,username,usercode, uuid FROM tp_v_admin WHERE uuid = '{0}' AND is_delete = 0", $uuid);
        $role = $this->V_Admin_model->single($sql);
        if (empty($role)) {
            exit(retJson(ErrCode::ErrCode_10403));
        }
        return $role;
    }
}
